package com.example.ui_demo_widget;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import com.example.ui_demo_widget.adapter.ClassroomBuildingAdapter;
import com.example.ui_demo_widget.pojo.ClassroomBuilding;

import java.util.ArrayList;

public class ListView4Activity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list_view2);

        ArrayList<ClassroomBuilding> ClassroomBuildings = new ArrayList<>();
        ClassroomBuildings.add(new ClassroomBuilding("-==选择教室==-", "", ""));
        ClassroomBuildings.add(new ClassroomBuilding("文友楼", "518", "多媒体教室"));
        ClassroomBuildings.add(new ClassroomBuilding("文友楼", "618", "多媒体教室"));
        ClassroomBuildings.add(new ClassroomBuilding("香远楼", "307", "普通教室"));
        ClassroomBuildings.add(new ClassroomBuilding("香远楼", "307", "普通教室"));
        ClassroomBuildings.add(new ClassroomBuilding("实验楼", "304", "计算机实验室"));
        ListView lv = findViewById(R.id.lv_contact);
        lv.setAdapter(new ClassroomBuildingAdapter(this, ClassroomBuildings));
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                ClassroomBuilding item = (ClassroomBuilding) lv.getItemAtPosition(i);
                Toast.makeText(ListView4Activity.this,
                        item.toString(),
                        Toast.LENGTH_SHORT).show();
            }
        });

    }
}